package com.aliengen.thingple.thingple.fillingstation;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.aliengen.thingple.thingple.AbstractThingpleActivity;
import com.aliengen.thingple.thingple.LoginActivity;
import com.aliengen.thingple.thingple.R;
import com.aliengen.thingple.thingple.SettingsActivity;

/**
 * This class is part of the Thingple mobile application for the CMC168 Handheld reader.
 *
 * Copyright AlienGen Limited 2016. All rights reserved.
 *
 * @author Timothé Mermet-Buffet <tim@aliengen.com>
 */
public class FillingStationActivity extends AbstractThingpleActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_filling_station);
        mApplication.getHandler().setOnEventListener(null);
        setOperatorName();
    }

    @Override
    public void onBackPressed() {
        this.finish();
        return;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            /*
            Snackbar.make(findViewById(R.id.filling_station_main_layout), "Settings of the handheld reader.", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
                    */
            Intent nextScreen = new Intent(getApplicationContext(), SettingsActivity.class);
            startActivity(nextScreen);
            return true;
        }

        if (id == R.id.action_logout) {
            mApplication.mService.api.disconnect();
            Intent nextScreen = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(nextScreen);
            this.finish();
            return true;
        }

        /*
        if(id == R.id.action_maintenance) {
            Intent nextScreen = new Intent(getApplicationContext(), MaintenanceActivity.class);
            startActivity(nextScreen);
            this.finish();
            return true;
        }

        if(id == R.id.action_tests) {
            Intent nextScreen = new Intent(getApplicationContext(), UpdateActivity.class);
            startActivity(nextScreen);
            return true;
        }*/

        return super.onOptionsItemSelected(item);
    }

    public void onClickCheckIn(View view){
        Intent nextScreen = new Intent(getApplicationContext(), TruckActivity.class);
        nextScreen.putExtra("operation", "checkin");
        startActivity(nextScreen);
    }

    public void onClickCheckOut(View view){
        Intent nextScreen = new Intent(getApplicationContext(), TruckActivity.class);
        nextScreen.putExtra("operation", "checkout");
        startActivity(nextScreen);
    }

    public void onClickSingleRead(View view){
        Intent nextScreen = new Intent(getApplicationContext(), SingleReadActivity.class);
        startActivity(nextScreen);
    }
}
